let hash = new Map()
var encode = function(longUrl) {
    let chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ-~'.split(''),
        radix = chars.length,
        qutient = hash.length - 1,
        arr = [];
    do {
        mod = qutient % radix;
        qutient = (qutient - mod) / radix;
        arr.unshift(chars[mod]);
    } while (qutient);
    hash.set(arr.join(''), longUrl);
    console.log(hash);
    return 'http://tinyurl.com/' + arr.join('')
};
// console.log(encode("https://baidu.com/news"))
// console.log(encode("https://baidu.com/about"))
/**
 * Decodes a shortened URL to its original URL.
 *
 * @param {string} shortUrl
 * @return {string}
 */
var decode = function(shortUrl) {
    // var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ-~',
    //     radix = chars.length,
    //     number_code = String(number_code),
    //     len = number_code.length,
    //     i = 0,
    //     origin_number = 0;
    // while (i < len) {
    //     origin_number += Math.pow(radix, i++) * chars.indexOf(number_code.charAt(len - i) || 0);
    // }
    shortUrl = shortUrl.replace(/http:\/\/tinyurl\.com\//, '')
    return hash.get(shortUrl)
};

/**
 * Your functions will be called as such:
 * decode(encode(url));
 */

function to36(number) {
    var chars = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ-~".split("");
    var jz = chars.length;
    var res = '';
    do {
        var mod = number % jz;
        res = chars[mod] + res;
        number = (number - mod) / jz;

    } while (number > 0)
    return res
}
let hash = new Map();
let baseUrl = "http://tinyurl.com/";

function encode(url) {
    var chars = "0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ-~".split("");
    var jz = chars.length;
    var res = '';
    var number = hash.length;
    do {
        var mod = number % jz;
        res = chars[mod] + res;
        number = (number - mod) / jz;

    } while (number > 0);
    hash.set(res, url);
    return baseUrl + res
}

function decode(url) {
    var res = url.replace(baseUrl, '');
    return hash.get(res)
}